package com.tjnu.losca.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tjnu.losca.core.ResponseVO;
import com.tjnu.losca.pojo.TeacherJournal;
import com.tjnu.losca.service.TeacherJournalService;
import io.minio.errors.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

@RestController
@RequestMapping("/teacherJournal")
public class TeacherJournalController {
    @Autowired
    TeacherJournalService teacherJournalService;

    @PostMapping("/add")
    public ResponseVO<Boolean> add(TeacherJournal teacherJournal){
        return ResponseVO.success("添加日志成功",teacherJournalService.save(teacherJournal));
    }

    @GetMapping("/del")
    public ResponseVO<Boolean> del(Integer id) {
        return ResponseVO.success("删除成功", teacherJournalService.del(id));
    }

    @GetMapping("/getAll")
    public ResponseVO<IPage> getAll(@RequestParam(defaultValue = "1") int pageNum,
                                    @RequestParam(defaultValue = "3") int pageSize,
                                    @RequestParam(defaultValue = "-1") String teacher,
                                    @RequestParam(defaultValue = "-1") String department) throws Exception {
        return ResponseVO.success("获取成功", teacherJournalService.getTeacherJournal(pageNum, pageSize,teacher,department));
    }

    @GetMapping("/recovery")
    public ResponseVO<Boolean> recovery(Integer id){
        return ResponseVO.success("恢复成功",teacherJournalService.recovery(id));
    }

    @PostMapping("/update")
    public ResponseVO<Boolean> update(TeacherJournal teacherJournal){
        return ResponseVO.success("修改日志成功", teacherJournalService.updateById(teacherJournal));
    }

    @PostMapping("/save")
    public ResponseVO<Boolean> save(TeacherJournal teacherJournal) throws InvalidBucketNameException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidPortException, InvalidKeyException, InvalidEndpointException, InvalidResponseException, XmlParserException, InternalException {
        return ResponseVO.success("保存成功", teacherJournalService.save(teacherJournal));
    }

    @GetMapping("/getJournalById")
    public ResponseVO<TeacherJournal> getJournalById(Integer id) {
        return ResponseVO.success("成功", teacherJournalService.getById(id));
    }
}
